Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ResourceLimiterAsync, which can yield until resource is available #3393

Merged
merged 29 commits into from
Oct 25, 2021

Conversation

pchickey
Copy link
Contributor

@pchickey pchickey commented Sep 29, 2021

This PR:

  • Moves ResourceLimiter's definition from wasmtime_runtime to wasmtime
  • Adds an additional ResourceLimiterAsync, which is just like a ResourceLimiter except the memory_growing and table_growing methods are async (via #[async_trait]). This is so that async embeddings of wasmtime can handle memory or table growing by awaiting for a resource to be available.
  • In order for the ResourceLimiterAsync methods to await inside memory & table grows, we need to add async variants of Memory::new, Memory::grow, Table::new, and Table::grow. These variants are not required for all async Stores, only for stores which are given a Store::limiter_async. So, this won't break any existing code.
  • Both ResourceLimiter traits now get table_grow_failed, which corresponds to memory_grow_failed. Better to just get this over with now than have to add it in later.
  • Test suite covers table limiting and async and panics now.

I had to restructure a fair bit of the interface between runtime and wasmtime for this PR, including extending the wasmtime_runtime::Store trait, and changing the error type passed between them to anyhow::Error instead of Box<dyn std::error::Error + Send + Sync>.

Additionally, both ResourceLimiters are now safer: wasmtime_runtime now catches any panics that occur from the user's impl of the traits.

@github-actions github-actions bot added fuzzing Issues related to our fuzzing infrastructure wasmtime:api Related to the API of the `wasmtime` crate itself labels Sep 29, 2021
@github-actions
Copy link

Subscribe to Label Action

cc @fitzgen, @peterhuene

This issue or pull request has been labeled: "fuzzing", "wasmtime:api"

Thus the following users have been cc'd because of the following labels:

  • fitzgen: fuzzing
  • peterhuene: wasmtime:api

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

crates/runtime/src/instance/allocator.rs Outdated Show resolved Hide resolved
crates/runtime/src/memory.rs Outdated Show resolved Hide resolved
crates/runtime/src/lib.rs Outdated Show resolved Hide resolved
crates/runtime/src/instance.rs Outdated Show resolved Hide resolved
crates/runtime/src/table.rs Outdated Show resolved Hide resolved
crates/wasmtime/src/limits.rs Outdated Show resolved Hide resolved
crates/wasmtime/src/limits.rs Outdated Show resolved Hide resolved
crates/wasmtime/src/memory.rs Outdated Show resolved Hide resolved
crates/wasmtime/src/store.rs Outdated Show resolved Hide resolved
crates/wasmtime/src/store.rs Outdated Show resolved Hide resolved
@pchickey pchickey force-pushed the pch/async_limiting branch 2 times, most recently from 1e14251 to 7d0611b Compare October 20, 2021 23:53
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good to me! If you're up for it I think it would also be interesting to have tests which panic! in the memory growth (either in the async or sync version) from the custom trait implementation which then asserts that the panic can be caught from the other side of wasm and handled.

crates/fuzzing/Cargo.toml Outdated Show resolved Hide resolved
crates/fuzzing/src/oracles.rs Outdated Show resolved Hide resolved
crates/runtime/src/instance/allocator.rs Outdated Show resolved Hide resolved
crates/runtime/src/memory.rs Outdated Show resolved Hide resolved
crates/wasmtime/src/instance.rs Outdated Show resolved Hide resolved
crates/wasmtime/src/memory.rs Show resolved Hide resolved
crates/wasmtime/src/store.rs Show resolved Hide resolved
crates/wasmtime/src/store.rs Outdated Show resolved Hide resolved
@pchickey pchickey changed the title make it possible for ResourceLimiter to yield until resource is available Add ResourceLimiterAsync, which can yield until resource is available Oct 21, 2021
@pchickey pchickey marked this pull request as ready for review October 21, 2021 23:52
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good to me! A few minor things I might also ask for:

  • Doc updates to the blocking methods that they can panic for async stores with an async limiter configured
  • Could you add a test where the async-ness is exercised as well? I noticed most of them using the async trait were just async conditions, but could there be one which also sleeps or synchronizes with some other task or something like that?

crates/runtime/src/libcalls.rs Outdated Show resolved Hide resolved
crates/wasmtime/src/func.rs Outdated Show resolved Hide resolved
tests/all/limits.rs Show resolved Hide resolved
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Ok final nit I forgot from earlier, can you add this to the #[cfg]'d APIs so the feature requirement is rendered with rustdoc? Other than that looks good to go!

#[cfg_attr(nightlydoc, doc(cfg(feature = "async")))]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fuzzing Issues related to our fuzzing infrastructure wasmtime:api Related to the API of the `wasmtime` crate itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants